package com.longblog.web.service.login;

import com.longblog.vo.UserVO;
import com.longblog.web.dao.user.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LoginService {

    @Autowired
    private UserDao userDao;
    /**
     * 登录校验
     * @author  lilonglong
     * @date 2019/10/8 18:41
     */
    public String login(String username,String password){
        if(username == null || "".equals(username) || password == null || "".equals(password)){
            return "用户名或密码不能为空";
        }
        List<UserVO> user = userDao.getUserByUserName(username);
        // 如果根据用户名未查询到用户，说明用户名错误
        if(user == null || user.size() == 0){
            return "用户名错误";
        }
        UserVO userVO = user.get(0);
        if(!password.equals(userVO.getPassword())){
            return "密码错误";
        }
        return "success";
    }
}
